using UnityEngine;
using UnityEngine.EventSystems;

public class DropItemArea : MonoBehaviour, IDropHandler, IEventSystemHandler
{
	public GUIItemLoader loader;

	public string Type;

	public void Start()
	{
	}

	public void OnDrop(PointerEventData data)
	{
		GUIItemEquipped itemEquipDrop = GetItemEquipDrop(data);
		if (itemEquipDrop != null)
		{
			if (Type == "Inventory")
			{
				if (itemEquipDrop.CurrentItemCollector != null)
				{
					UnitZ.playerManager.PlayingCharacter.inventory.UnEquipItem(itemEquipDrop.CurrentItemCollector);
				}
				return;
			}
			if (Type == "Ground" && itemEquipDrop.CurrentItemCollector != null)
			{
				UnitZ.playerManager.PlayingCharacter.inventory.DropItemByCollector(itemEquipDrop.CurrentItemCollector, itemEquipDrop.CurrentItemCollector.Num);
			}
		}
		GUIItemCollector dropItem = GetDropItem(data);
		if (dropItem != null)
		{
			if (dropItem.Type == "Ground" && Type == "Inventory" && dropItem.Item != null)
			{
				UnitZ.playerManager.PlayingCharacter.Interactive(dropItem.Item.Item.gameObject);
			}
			if (dropItem.Type == "Inventory" && Type == "Ground" && dropItem.Item != null)
			{
				dropItem.currentInventory.DropItemByCollector(dropItem.Item, dropItem.Item.Num);
			}
		}
	}

	private GUIItemCollector GetDropItem(PointerEventData data)
	{
		GameObject pointerDrag = data.pointerDrag;
		if (pointerDrag == null)
		{
			return null;
		}
		if ((bool)pointerDrag.GetComponent<GUIItemCollector>())
		{
			return pointerDrag.GetComponent<GUIItemCollector>();
		}
		return null;
	}

	private GUIItemEquipped GetItemEquipDrop(PointerEventData data)
	{
		GameObject pointerDrag = data.pointerDrag;
		if (pointerDrag == null)
		{
			return null;
		}
		if ((bool)pointerDrag.GetComponent<GUIItemEquipped>())
		{
			return pointerDrag.GetComponent<GUIItemEquipped>();
		}
		return null;
	}
}
